"""
主题: 将装饰器定义为类的一部分
问题: 你想在类中定义装饰器，并将其作用在其他函数或方法上。
提示 : 
"""


from functools import wraps

class A:
    # Decorator as an instance method
    def decorator1(self, func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            print('Decorator 1')
            return func(*args, **kwargs)
        return wrapper

    # Decorator as a class method
    @classmethod
    def decorator2(cls, func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            print('Decorator 2')
            return func(*args, **kwargs)
        return wrapper

a = A()
@a.decorator1
def spam():
    print('span')

# As a class method
@A.decorator2
def grok():
    print('grok')     

class Person:
    # Create a property instance
    first_name = property()

    # Apply decorator methods
    @first_name.getter
    def first_name(self):
        return self._first_name

    @first_name.setter
    def first_name(self, value):
        if not isinstance(value, str):
            raise TypeError('Expected a string')
        self._first_name = value
        
def recipe1():
    spam()
    grok()
        

def main():
    print('recipe1'.center(20, '*'))
    recipe1()


if __name__ == '__main__':
    main()              